package com.sojoys.artifact.manager;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ContextManager implements ApplicationContextAware{

	private ContextManager() {
	}

	private static ContextManager ME = new ContextManager();

	public static ContextManager me() {
		return ME;
	}
	
	private ApplicationContext ctx;  
	
//	@SuppressWarnings("resource")
	public void init(String path){
//		new FileSystemXmlApplicationContext(path);
		this.ctx = new ClassPathXmlApplicationContext(path);
	}
	
    public void setApplicationContext(ApplicationContext applicationContext) {  
    	this.ctx = applicationContext;  
    }  
    public ApplicationContext getApplicationContext() {  
        return ctx;  
    }  
    public <T> T getBean(String name, Class<T> clz) throws BeansException {  
        return ctx.getBean(name,clz);  
    }  
}
